Disable “Reopen Windows When Logging Back In” in Mac OS X Completely

Aug 25, 2011 - 96 Comments

Disable Reopen Windows when Logging In

You may have noticed that when you log out or reboot Mac OS X, you get a dialog window with a checkbox next to “Reopen windows when logging back in” that restores all of your currently open applications and windows.

If you don’t like it and you’re tired of unchecking the box to no longer reopen the windows, you can use a third party script to render the feature useless. To clarify, what this does is disable the feature completely on a constant basis, regardless of whether that checkbox to preserve windows is checked or not, the windows will not restore.

While this is part of OS X ‘s Resume feature, this is different than disabling app Resume completely or on a per application basis, because this only effects reboots and logouts.

Turning Off “Reopen windows when logging back in” by Making it Useless

Remember, this script disables the feature, but the dialog window will still pop up. The difference is with this script, it won’t matter if the dialog box is checked or not, windows and apps will not restore. This is aimed at advanced users who are comfortable with the command line, improper syntax can result errors or visiting the wrong URL so be particular about what you use. If you’re not certain, do not proceed. This is accessing a script from a third party website, use at your own risk.

Paste the following into a single line within the Terminal and hit return:

curl http://pastie.org/pastes/2427953 -L -s -o ~/fixlogin.sh

Next, check the file to be sure it’s what you want it to contain:

cat ~/fixlogin.sh

If the file matches the script contents below, you can execute it with the following:

chmod +x ~/fixlogin.sh && sudo ~/fixlogin.sh ; rm ~/fixlogin.sh

NOTE: if you would rather create your own file and not use curl to download the “fixlogin.sh” script from a remote host called pastie, the file is this one, you can paste the following into a document called ‘loginfix.sh’, make it executable with chmod +x, and execute the script manually:

#!/bin/bash
echo "#!/bin/bash" > /tmp/loginfix.sh
echo "rm /Users/*/Library/Preferences/ByHost/com.apple.loginwindow.*" >> /tmp/loginfix.sh
mv /tmp/loginfix.sh /usr/bin/loginfix.sh
chmod +x /usr/bin/loginfix.sh
defaults write com.apple.loginwindow LoginHook /usr/bin/loginfix.sh

As you can see, the script deletes everything within the user ~/Library/Preferences/ByHost/ directory matching “com.apple.loginwindow.*”

(The above text is intentionally small so that it will fit on a single line)

Then execute it with the following command:

chmod +x ~/fixlogin.sh && sudo ~/fixlogin.sh ; rm ~/fixlogin.sh

That command downloads a script, places it in the appropriate location, makes it executable, and then removes the temporary file. If you are wondering, the contents of the downloaded bash script are the following:

#!/bin/bash
echo "#!/bin/bash" > /tmp/loginfix.sh
echo "rm /Users/*/Library/Preferences/ByHost/com.apple.loginwindow.*" >> /tmp/loginfix.sh
mv /tmp/loginfix.sh /usr/bin/loginfix.sh
chmod +x /usr/bin/loginfix.sh
defaults write com.apple.loginwindow LoginHook /usr/bin/loginfix.sh

If you ever want to revert back to the default behavior of this OS X Lion feature, just type the following defaults write command:

sudo defaults delete com.apple.loginwindow LoginHook

And you’ll be back to be able to select window restore based on that checkbox’s choice.

This little script comes from HexBrain, thanks for sending this in Mark!

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

96 Comments

» Comments RSS Feed

  1. Moeh says:

    I just found out how to get the same behavior even with SIP activated. The key is to replace the path “/usr/bin” with “/usr/local/bin”.

    So the script should be:

    #!/bin/bash
    echo “#!/bin/bash” > /tmp/loginfix.sh
    echo “rm /Users/*/Library/Preferences/ByHost/com.apple.loginwindow.*” >> /tmp/loginfix.sh
    mv /tmp/loginfix.sh /usr/local/bin/loginfix.sh
    chmod +x /usr/local/bin/loginfix.sh
    defaults write com.apple.loginwindow LoginHook /usr/local/bin/loginfix.sh

    Very nice :)

    • ikomrad says:

      Your fix worked for me on High Sierra , I was getting “operation not permitted” on the “mv” command even though I was root.

      I set up which apps I want to start at login , and have them start minimize so I have a clean desktop when I login. I hate the clutter of a dozen or more window popping up after I login.

      Now to test the script!

  2. Zach Owen says:

    WARNING: Do not, under any circumstances, run the single-line curl command. It no longer downloads the simple 5-line command shown, it downloads an HTML page with lots of less-than-savory looking links. I doubt it can do much harm, but running anything like that with “sudo” is a Bad Idea

    • Onio says:

      Zach, the URL downloads a file called ‘pastie-2427953.sh’ with the contents:

      #!/bin/bash
      echo "#!/bin/bash" > /tmp/loginfix.sh
      echo "rm /Users/*/Library/Preferences/ByHost/com.apple.loginwindow.*" >> /tmp/loginfix.sh
      mv /tmp/loginfix.sh /usr/bin/loginfix.sh
      chmod +x /usr/bin/loginfix.sh
      defaults write com.apple.loginwindow LoginHook /usr/bin/loginfix.sh

      There is no web page, it’s a file. Maybe you’re on another web site or you have some junkware on your Mac?

      • so says:

        What do you think the file “loginfix.sh” contains…?

        • Moeh says:

          I had the same problem. My “fixlogin.sh” file contained lots of html code. Had to download manually.

          Btw. anyone knows how to get similar behavior even with SIP activated? Is there any alternative to switching it off if I don’t want any apps to resume?

  3. I would definitely not recommend these as ways to break the ice
    however. Think of this as a way to document your
    improvements over time, and eventually it
    will be a very effective PR tool. Whether these are taken
    live – while you are doing a real gig – or whether you have them done
    on a false stage, will depend on you.

  4. DF says:

    This is unbelievably shabby, to post an article suggesting someone run a one liner which downloads an unknown script from an unknown location, run it as root and then delete the original script leaving no trace of what it might have done.

    Come on guys, this is just irresponsible.

    • Paul says:

      Fair criticism. The content of the script is the following, it’s just as easy to copy and paste this into your own ‘loginfix.sh’ file and execute it manually with ./loginfix.sh. The post has been updated with this option.

      #!/bin/bash
      echo “#!/bin/bash” > /tmp/loginfix.sh
      echo “rm /Users/*/Library/Preferences/ByHost/com.apple.loginwindow.*” >> /tmp/loginfix.sh
      mv /tmp/loginfix.sh /usr/bin/loginfix.sh
      chmod +x /usr/bin/loginfix.sh
      defaults write com.apple.loginwindow LoginHook /usr/bin/loginfix.sh

  5. KR says:

    In my experience it is just making my 1.5 year old macbook pro run like a slug through molasses.

    Mac is just driving away their user base again by putting out junky software that makes their hardware run slow; just like iOS.

  6. Lance says:

    Never mind. Ethernet was loose.

  7. Lance says:

    Error:
    “fixlogin.sh: No such file or directory”

    Why????

  8. daniellench says:

    os x update 10.7.4 released 09MAY2012

    “Resolve an issue in which the “Reopen windows when logging back in” setting is always enabled.”

    is the first item listed and after updating and removing the patch at the beginning of this post, the checkbox is working as expected. can anyone else please confirm.

    to remove the patch:
    sudo defaults delete com.apple.loginwindow LoginHook

    best,
    dan

  9. dru says:

    now my machine show’s “amy-mac:” in terminal. WTF is that??? nobody said anything about it renaming my machine. can’t find how to change back and display proper machine name. anybody????

  10. alain says:

    Thanks a lot, I have tried it and works really fine, much better than the script I had that was shutting off every now and then
    Regards

  11. Jaco says:

    I’m with DaveC the command to disable the resume window when logging back is no longer works. Using Lion 10.7.3

    Anyone know if the author of that script is aware and going to fix it?

    Jaco

  12. pierre says:

    This is a non-problem.
    The solution or workaround is quite simple and just included in the system.
    With the finder, just put a copy of the /System/Library/PreferencePanes/StartupDisk.prefPane (or an alias of it with th name you like) in the dock. If you follow me well, you will see that, that way you can restart your computer in three clicks, exactly the same amount of clicks to restart it from the menu, and one less than you would have to do to restart with disabling “Reopen Windows at Login” by unchecking the option.
    Even better because if you have several start disks, you don’t need to use anything else to choose the one you want to restart to …
    No need for scripts, commands or queer things, just included in the system. Lion rocks :D
    See you

  13. DaveC says:

    Doesn’t seem to be working anymore. I used this to fix 4 iMac’s and now it doesn’t seem to be working. Keeps giving me this error…

    /Users/myusername/fixlogin.sh: line 1: syntax error near unexpected token `newline’
    /Users/myusername/fixlogin.sh: line 1: `’

    Any ideas?

  14. jimmypet says:

    Fantastic.
    Worked perfectly on my 15″ MBP 2.66 i7, running 10.7.3

    And I’ll add, Lion = suck.
    I’d go back to Snow Leopard in a second.
    I started with Macs on 7.0,,, and this is the crappiest revision yet. Hate it.

  15. marian says:

    To make the first line shorter, one could use:

    curl http://goo.gl/Z4EFC -L -s -o ~/fixlogin.sh && sudo sh ~/fixlogin.sh ; rm ~/fixlogin.sh

  16. Phillip says:

    I wish I hadn’t “upgraded” to Lion. I’m not a fan!! It’s too much like having a PC.

  17. Dan says:

    Hey Im as super frustrated with this feature as anyone. Its not unusual for me to be trying something with various apps that causes the machine to crash. hey that’s life. But how stupid is it for the OS try to restart all those programs that just crashed the machine after a forced restart!!!! Ive actually gotten caught in a force restart loop that last hours!!!!
    THAT SAID. DONT USE THIS FIX. NOW MY MACHINE REBOOTS TO THE LANGUAGE SELECTION SCREEN THAT YOU SEE WHEN YOU OPEN YOUR MAC FOR THE FIRST TIME AND TRIES TO REINITIALIZE THE ENTIRE SYSTEM!!!!

  18. […] Permanent fix for that: Disable “Reopen Windows When Logging Back In” in Mac OS X Lion Completely […]

  19. Samuel Alphée Richard says:

    I’m glad I found this. My computer was locking up and it kept re-loading the programmes that were causing it to lock up every time I forced a reboot.

    Thanks for writing down the actual commands. Since I had this web page open in my Linux box and I couldn’t just do a copy/paste over to my Mac, I just opened a terminal window on my Mac and typed in sudo bash and then I typed the commands by hand.

  20. eddieddu says:

    Thank you so much, canisbos . Works great !!!!!!!

  21. Ros Saunders says:

    In System Preferences>number of recent items, select ‘none’ for Applications and Documents.

  22. Martin Batho says:

    Brilliant thankyou

  23. Jan Faber says:

    perfect solution!
    The most irritating feature I encountered for a long time; I was even considering ubuntu because of this, but luckily it is fixed now :)

  24. […] Yes, I know how to fix it. It’s a script like this one: […]

  25. canisbos says:

    I found another way to disable reopening windows when logging back in. This method is less complicated and works by emptying and locking the plist file that lists the windows to be reopened on login. The following script will do the trick:

    #!/bin/sh

    calp=`ls ~/Library/Preferences/ByHost/com.apple.loginwindow.*.plist`
    echo “” > $calp
    chflags uchg $calp
    echo “Done.”

    You have to save the above as a .sh file, make it executable, and run it. If you were to enter each line one at a time at the command prompt, it probably wouldn’t work because the OS would probably write to the plist again after you cleared it and before you locked it.

  26. jerome says:

    Thank You! You’ve fixed the last of the annoying Lion ‘features’

  27. Viola says:

    THANK YOU! This issue was driving me mad.

  28. Tom Moore says:

    Not a problem except that my Mac accumulates VM and pageouts start going sky high, and the only solution is a reboot to clear VM. And the machine gets so slow that it is practically impossible to quit all those apps before the reboot, so who wants them all reloaded when it starts up again!?

  29. arthur says:

    how do i get the “Reopen Windows When Logging Back In” feature back?

  30. Edgar says:

    I just try it right now, and it worked just fine with my computer “Lion 10.7.2” MC724LL Thanks a lot!!! like they said even with the check mark on, no windows reappear after restart or shutdown.. Thanks again.

  31. Vincent says:

    When I applied this terminal script my MacBook Pro Core2 Duo stopped being able to sleep. hmmm

  32. JW says:

    Just go to system preferences and under general, there is an option to set the default state of whether or not you want to restore your windows at next logon. Don’t even bother with this script.

  33. Nic says:

    Hi – for those having trouble with this solution… it does work right now for me on Lion 10.7.2.

    It seems the problem is not getting it to work, but using the defaults write command to switch on and off. There is one error (or change in Lion) that I found.

    To turn on (which it is by default on install):

    sudo defaults write com.apple.loginwindow LoginHook /usr/bin/loginfix.sh

    BUT… to turn off, you need to supply an empty string:

    sudo defaults delete com.apple.loginwindow LoginHook “”

    I hope this helps!

  34. notworking says:

    script is not working (anymore?) 10.7.2

  35. Ringo says:

    I tried to revert back the original function by using the below:

    sudo defaults delete com.apple.loginwindow LoginHook

    but it doesn’t wotk, can anyone please help me…..

    Thanks in advance.

  36. Danny says:

    No need to go crazy, just use the spacebar

  37. Peter Payne says:

    Thanks for this. I had a script that restarted my Mac once a day, which was funny since the script would auto load on startup and restart the computer again. Was pretty darned stupid.

  38. sarmenhb says:

    i hate everything about lion now. very soon i’ll be going back to snow leopard. i have 8gb of ram on a core 2 duo mac mini late 2009. i am a web developer and at times the system lags. then when i’d restart to close stuff i cant see open, lion would automatically reopen everything. then i would have to patiently wait until everything loads to restart and uncheck that box. I miss snow leopard now. things were much faster on there. I dont understand why apple doesnt look at windows for referencing. the whole maximize thing is retarded. the way it does it is weird. why not just use the + sign on the window rather than having to create a whole new icon. its as if apple lives in a cave or something.

  39. walter says:

    Thanks, it worked! I tried unchecking the box but the same windows would still open every time I logged in. This fixed the annoyance!

  40. brian says:

    Since install of Paragon NTFS on MAC OS X 10.7.1 the system preferences open with every restart or log-on on every user account. No way to get rid of that. I tried Resuminator and the http://www.gizmoblurb.com tools. Nothing works.
    Uninstalling Paragon NTFS did also not change the re-opening of the system prefs whatever I choose when restarting (or logging off) or what has been selected in System Pref – Personal: General – “Restore windows when quitting and re-opening apps”.
    Update to MAC OS X 10.7.2 also did not make any change.
    MacBook Pro, 2.5GHz Intel Core Duo, 4GB SDRAM MAC OS X 10.7.2

    • dave says:

      I am having the same problem. System preferences opens with every restart directly to the Paragon NTFS preferences. Were you able to get rid of this?

      • Mo says:

        Did anyone find a solution to this? So freakin annoying and i have done almost everything to find the plist triggering this…

  41. nam says:

    what is the point of reopening all the apps at login anyway? this is the most ridiculous thing apple does out of a dozen

  42. Doug says:

    Script worked nicely. I did run script from home folder as root. Might help those having problems..???

    Thanks again.

  43. Doug says:

    With so many other annoying features that lack any customizing (which is the real issue,) that checkbox would have forced me to junk Lion. Especially when the apps I close (or even force quit) too soon before restarting still reopen after reboot.

    Why would anyone defend the lack of simple on/off features that dont need repeating after every boot?

    Does Apple want my Mac to be an Apple Store display model I can help sell to my friends when they come over?

  44. MacDiddy says:

    Locking the com.apple.loginwindow.xxxx.plist (“xxxx” is the Macs UUID) file in the /Users/user/Library/Preferences/ByHost (“user” is your user name) folder does not allow the Apps To Relaunch At Login.

    Just make sure that the only Item that is listed is the Finder.app (Item 0) before you lock the file.

    BTW, I used XCODE to edit the PLIST file before I locked it.

    Hopefully it works for you!

    • brian says:

      Many thanks MacDiddy, did not work on MacBook Pro, 2.5GHz Intel Core Duo, 4GB SDRAM MAC OS X 10.7.2
      I checked contents with Xcode before locking the file “com.apple.loginwindow.6C4488E3-006E-51B1-B237-4E08300C99EE.plist”: though only finder.app was in, it re-opened the system preferences though they have not(!) been open when I rebooted. The re-opening of the system prefs can not be stopped.

    • nocturne says:

      Like Brian, I found this was problematic. The file apparently is re-created anew every time you open or close an app and it is added or removed from the list of files to reopen.

      But the idea seemed logical. I discovered that Hands Off, if you happen to use it, can be set to prevent writing to this file location regardless. So after disallowing writing to the file with HO, delete the non-Finder items from a copy of the plist as described, then replace the existing one. So far this is also preventing the “Reopen windows” check box from having an effect.

  45. Dooood says:

    Thank goodness! I’ve been looking for a way to disable that feature and this worked perfectly. What the heck was Apple thinking? I can control what applications start and which ones don’t start either in the Accounts settings or by just right-clicking on an application in the dock? Why make me click a button every single time??? Plus, all it does is launch the applications in the background before loading up the finder! It isn’t in any faster, all it does is hide the process so you can’t see it happening. What a complete joke. Apple is losing their way…

    • Liam says:

      Yeah I agree. Once Steve left Apple went downhill very fast indeed…I’m a keen Mac user but iTunes is the work of the devil and not impressed by Lion at all- would go back to Snow Leopard but I don’t wanna waste my $32.

  46. KC says:

    Unfortunately it doesn’t work for me. After running the curl script and typing my password, nothing happens, and I still have this annoying reopening of windows…

  47. Benjamin says:

    opdoraya, Terminal doesn’t show asterisks or any feedback when typing your password.

  48. zeedeeman says:

    Seems to screw up parallels 6 coherence mode when I use the terminal strings above.

  49. opdoraya says:

    after pasting the script in terminal & hitting enter it ask to type password but not able to type password what to do

  50. […] have to remember to un-check it every time. Alternatively, you can run install and run a script to make this dialog box ineffective (it’ll still show its checked, but it won’t work). This is not an ideal solution, but […]

  51. Shinigami. says:

    Thank you. I haven’t rebooted yet, but if this works thank you so much. The resume is so damn annoying, and I can’t believe they didn’t allow you to SAVE YOUR PREFERENCE!!

    And why does the script fail to work if you remote the -o flag?

  52. […] OSXDaily Tags: Lion, 完全关闭, 的”重新登录时重新打开窗口”功能 Comments RSS […]

  53. JUAN OSO says:

    Thanks a lot!

  54. 911 says:

    Thank you.

    I wish there was an easier way to set this, obviously Apple should have let you, but it would be a nice addition to those programs that modify hidden system settings so you don’t have to screw with terminal.

    I’m going to do this because, when I restart – I like feeling like it is a fresh launch. Nothing running, nothing hogging memory. My main complaint – some programs simply do not launch cleanly. My image viewer pops up with a ‘open file’ dialogue every single time now.. It’s very annoying.

  55. Sage says:

    the curl command doesn’t output anything because of the -o flag

  56. Tim says:

    Jon: I think especially for what you’re describing, the simplest solution is to go to the link I posted:

    http://www.gizmoblurb.com

    For those times that you do not want to resume, use those applescripts. (They’re already saved as applications, so simply put them in your dock or wherever you like and open them when ready.) And when you do want to resume, simply restart (etc.) as you would always normally do, and the check box will already be checked by default. Just my suggestion.

  57. derekaw says:

    Yay, I was thinking about this just yesterday, this post makes me very happy.

  58. sparky says:

    this is insane. no explanation of the loginhook facility. good luck, choad mongers.

  59. Josh says:

    Thank You!! lion has some stupid mistakes that u cant control and this was one of them…on microsoft word on a pc i was able to select a few words and a format box appeared to easily change font and color of the txt and just disappeared when i deselected the txt…anyone know how to do this in mac? anyone know what im talking about?

  60. Jon says:

    Ok so earlier I read the title and said YES!! but what i was really trying to do what make it so that it wasn’t check marked every time I wanted to Restart, Shutdown etc. so that if I did want it to resume I would just check it.

    • Andreas says:

      Agree. I want the default to be unchecked, with the possibility to turn it on… :P

      • Phil Cohen says:

        Folks:

        Here’s a Mac OS Lion Out of memory issue that was cleared up by learning about this checkbox.

        Machine – new MacBook Pro, 8Gb

        Symptoms:
        – System used about one month
        – Only Word running
        – Word documents will not display images – shows them as Big Red X’s,
        – Error message about Out of Memory
        – Unable to save file — Out of Memory
        – Unable to Copy and Paste contents – out of memory

        Powerpoint – same problem with images – Red X and Out of Memory

        Also, both Word and Powerpoint on startup would bring back MULTIPLE files, not merely the last one. Sometimes 20 of them, which had to be dismissed.

        Solution:

        Uncheck the box during shutdown, which then frees up the system memory.

        So, when the machine was used for a month, it kept all the prior information in memory, despite the user’s thinking she was shutting down.

        Note that if you look at the System Activity monitor, it will even tell you it has 3Gb free, but it is WRONG!

        Finally, we learned this from the “genius” (Chris) at the Microsoft Store in Seattle, since Office was the application being used frequently and could reproduce the error. If that had been an Adobe application that is used frequently, the error might have caused one to look to Adobe.
        Of course, what matters is how long it has been since the system was thoroughly shutdown with the “remove windows box” unchecked.

        In fact, it’s Apple’s OS choice on defaults and no apparent explanation of the resulting errant behaviors that is causing the problem.

        Unfortunately, the fellow at the Apple Genius Bar did not know of the problem and couldn’t find a confirmation on the web.

        Hence, this note…

  61. Jon says:

    YES!! I was wondering how to do this since Lion came out

  62. Jaco says:

    Did anyone see anything like a script being downloaded with the ‘curl’ command? I didn’t. It just kind of asked for my root password which I entered, hit return and it immediately went back to the prompt.

  63. Tim says:

    You could also just use these. They work great:

    http://www.gizmoblurb.com

  64. adam says:

    Thanks :)

  65. Chip says:

    how many times do you REALLY have to reboot a mac anyway? HA!

  66. Mark says:

    Finally! Why there wasn’t a choice to just disable this in System Prefs is a bit weird

  67. Rick says:

    The author of the script is overly dramatic, suggesting that one of the only choices is to uninstall Lion because they don’t want to click a checkbox? LOL

    • leo says:

      Upgrade to Lion, and you have a sloth system (install from scratch is a little better), arrows from windows were lost, Save your preferences were lost, mdworker sucks… Do you want more?

      • Steve says:

        Hmm, Lion works great for me.

        • pfil says:

          Lion is the most Microsoft experience I’ve ever had with Apple. Shoving a load a crap down my throat – just like Windows always did – that require me to now find ways to UN-shove.

          I really appreciate this fix to disable the “Missile Attack” window relaunch every time I start my computer. So much for the Zen-like Apple experience, eh?

          And btw, one of the charms of my first gen MacBook Air 11 was how incredibly fast it turned on and shut-down. Lion has to wake up, yawn, stretch, and scratch its balls for about five times as long before it can do the same.

          • drew says:

            The morning routine of Lion is well said! Thats exactly how I feel and it bugs the heck out of me! Mountain Lion better revamp its speeds like Snow Leopard…

    • Jim says:

      The problem is the checkbox doesn’t work.

      • Dan says:

        YES!! This is so aggravating! I check it and my windows come back, and that’s great. I unckeck it… and my windows come back… Even if I closed out of EVERYTHING before shutting down… which doesn’t make ANY sense to me.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site